package com.ruoyi.devops.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.devops.domain.InspectionAdg;
import com.ruoyi.devops.domain.InspectionTask;
import com.ruoyi.devops.domain.InspectionTemplate;
import com.ruoyi.devops.domain.vo.InspectionAdgVO;
import com.ruoyi.devops.mapper.InspectionAdgMapper;
import com.ruoyi.devops.mapper.InspectionTaskMapper;
import com.ruoyi.devops.mapper.InspectionTemplateMapper;
import com.ruoyi.devops.service.IInspectionAdgService;
import com.ruoyi.devops.service.IInspectionTaskService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@Service
public class InspectionAdgService extends ServiceImpl<InspectionAdgMapper, InspectionAdg> implements IInspectionAdgService {
    @Resource
    InspectionAdgMapper inspectionAdgMapper;
    public List<InspectionAdg> queryInspectionAdgTemplate(InspectionAdgVO inspectionAdg) {


        QueryWrapper wrapper = new QueryWrapper<InspectionAdg>();

        String getLocal = inspectionAdg.getLocal();
        String getModel = inspectionAdg.getModel();
        String getReason = inspectionAdg.getReason();
        String times = inspectionAdg.getPatrolStart();
        String timee = inspectionAdg.getPatrolEnd();
        String getDescription = inspectionAdg.getDescription();

        if (StringUtils.isNotEmpty(getLocal) && !"null".equals(getLocal)) {
            wrapper.like("local",getLocal);
        }
        if (StringUtils.isNotEmpty(getModel) && !"null".equals(getModel)) {
            wrapper.like("model",getModel);
        }
        if (StringUtils.isNotEmpty(getReason) && !"null".equals(getReason)) {
            wrapper.like("reason",getReason);
        }
        if (StringUtils.isNotEmpty(getDescription) && !"null".equals(getDescription)) {
            wrapper.like("description",getDescription);
        }

        if (StringUtils.isNotEmpty(times) && !"null".equals(times)) {

            times = times + " 00:00:00";
            wrapper.gt("time",times);
        }
        if (StringUtils.isNotEmpty(timee) && !"null".equals(timee)) {
            timee = timee + " 23:59:59";
            wrapper.lt("time",timee);
        }

        wrapper.like("status","0");
        List<InspectionAdg> list = inspectionAdgMapper.selectList(wrapper);
        return list;

    }

    public InspectionAdg queryInspectionAdgTemplateById(InspectionAdg inspectionAdg) {
        String id = inspectionAdg.getId();

        InspectionAdg re = inspectionAdgMapper.selectById(id);
        return re;
    }

    public int scInspectionAdgTemplate(InspectionAdg inspectionTask) {
        int b = inspectionAdgMapper.updateById(inspectionTask);
        return b;
    }

    @Override
    public int scInspectionAdgTemplatemodel(InspectionAdg inspectionTask) {
        int b = inspectionAdgMapper.updateById(inspectionTask);
        return b;
    }

    public int delInspectionAdgTemplate(InspectionAdg inspectionAdg) {

        String id = inspectionAdg.getId();
        inspectionAdg.setStatus("1");
        return inspectionAdgMapper.updateById(inspectionAdg);
    }

    public int scInspectionQhTemplate(InspectionAdg inspectionAdg) {
        //修改状态
        inspectionAdgMapper.updateFlag();
        inspectionAdg.setFlag("0");
        return inspectionAdgMapper.updateById(inspectionAdg);
    }


}
